package com.ruoyi.spicfz.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.spicfz.domain.Parent;
import com.ruoyi.spicfz.service.IParentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 个人主信息Controller
 * 
 * @author ruoyi
 * @date 2021-08-28
 */
@Controller
@RequestMapping("/spicfz/parent")
public class ParentController extends BaseController
{
    private String prefix = "spicfz/parent";

    @Autowired
    private IParentService parentService;

    @RequiresPermissions("spicfz:parent:view")
    @GetMapping()
    public String parent()
    {
        return prefix + "/parent";
    }

    /**
     * 查询个人主信息列表
     */
    @RequiresPermissions("spicfz:parent:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Parent parent)
    {
        startPage();
        List<Parent> list = parentService.selectParentList(parent);
        return getDataTable(list);
    }

    /**
     * 导出个人主信息列表
     */
    @RequiresPermissions("spicfz:parent:export")
    @Log(title = "个人主信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Parent parent)
    {
        List<Parent> list = parentService.selectParentList(parent);
        ExcelUtil<Parent> util = new ExcelUtil<Parent>(Parent.class);
        return util.exportExcel(list, "个人主信息数据");
    }

    /**
     * 新增个人主信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存个人主信息
     */
    @RequiresPermissions("spicfz:parent:add")
    @Log(title = "个人主信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Parent parent)
    {
        return toAjax(parentService.insertParent(parent));
    }

    /**
     * 修改个人主信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Parent parent = parentService.selectParentById(id);
        mmap.put("parent", parent);
        return prefix + "/edit";
    }

    /**
     * 修改保存个人主信息
     */
    @RequiresPermissions("spicfz:parent:edit")
    @Log(title = "个人主信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Parent parent)
    {
        return toAjax(parentService.updateParent(parent));
    }

    /**
     * 删除个人主信息
     */
    @RequiresPermissions("spicfz:parent:remove")
    @Log(title = "个人主信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(parentService.deleteParentByIds(ids));
    }
}
